package part8;

/**
 * @author wcj
 * @Date 2021/5/16 17:13
 * @Version 1.0
 */
public class Part84 {

    public static void main(String[] args) {
        Super aSuper = new Sub();
        // 注意多态体现在方法上，而不是域值的调用上，域值的调用是由编译器完成的，aSuper编译时类型为Super,多态的运行时类型为Sub
        System.out.println("sup.field=" + aSuper.field + ",sup.getField=" + aSuper.getField());
        Sub sub = new Sub();
        System.out.println("sub.field=" + sub.field + ",sub.getField=" + sub.getField() + ",sub.getSuperField=" + sub.getSuperField());
    }
}

class Super {
    public int field = 0;

    public int getField() {
        return field;
    }
}

class Sub extends Super {
    public int field = 1;

    @Override
    public int getField() {
        return field;
    }

    public int getSuperField() {
        return super.field;
    }
}
